<template>
	<el-table
	v-if="ifshow"
	  :data="
	    tableChildData
	  "
	  :stripe="stripe"
	  :current-page.sync="currentPage"
	  style="width: 100%"
	>
	 <el-table-column prop="desp" label="区划" width="120">
	    </el-table-column>
	      <el-table-column prop="jgname" label="机构名称" width="300">
	      </el-table-column>
	   <el-table-column prop="jgsySystemCode" label="系统类别" width="100">
	   </el-table-column>
	   <el-table-column prop="jfxs" label="经费形式" width="120">
	   </el-table-column>
	 <el-table-column prop="sydwhyfl" label="事业单位行业类别" width="120">
	 </el-table-column>
	 <el-table-column prop="ldzscount" label="领导数量" width="120">
	 </el-table-column>
	 
	
	</el-table>
	
  <el-table
  v-else
    :data="
      tableData
    "
    :stripe="stripe"
    :current-page.sync="currentPage"
    style="width: 100%"
  >
    <el-table-column prop="ldzsname" :label="firstName" width="180">
    </el-table-column>
 
    <el-table-column prop="ldzscount" :label="lableName"> 
	<template #default="props">
			<el-link type="primary" @click="changehandle(props.row.ldzsname)" :disabled="ifshow" >{{props.row.ldzscount}}
				</el-link>
		</template>
	</el-table-column>
  </el-table>
  <div class="pagination">
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :page-sizes="[12, 20]"
      :page-size="pagesize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination>
  </div>
</template>
<script>
import Sever from "@/api/selfApi.js";
export default {
  props: ["depCode", "ldzstype"],
  data() {
    return {
		firstName:"领导名称",
		ifshow:false,
      lableName: "",
      stripe: true, //是否为斑马纹 table
      tableData: [],
      currentPage: 1,
      pagesize: 12,
      total: 0,
	  val:"",
    };
  },
  methods: {
   handleSizeChange(val) {
   	 this.pagesize = val;
   	 if(this.ifshow){
   		 this.handle(this.val,this.currentPage,this.pagesize);
   		 
   	 }else{
   		this.refreshData(this.depCode, this.ldzstype,this.currentPage,this.pagesize); 
   	 }
   	
     
   },
   handleCurrentChange(val) {
   	this.currentPage = val;
   	if(this.ifshow){
   				this.handle(this.val,this.currentPage,this.pagesize);
   	}else{
   				this.refreshData(this.depCode, this.ldzstype,this.currentPage,this.pagesize); 
   	}
      
   },
    async refreshData(depCode, ldzstype,currentPage,pagesize) {
      if (depCode == "") {
        depCode = "36%";
      }
      if (ldzstype == "bz") {
        this.lableName = "领导核编数量";
      } else if (ldzstype == "zz") {
        this.lableName = "领导在编数量";
      } 
      await Sever.smz
        .getSyjgLdzsChild({ depCode: depCode, ldzstype: ldzstype,pageNum:currentPage,pageSize: pagesize })
        .then((res) => {
          if (res.code == 1) {
            if (res.data != null) {
				console.log(res.data);
            this.tableData = res.data.list;
            this.total = res.data.total;
            } else {
              this.tableData = [];
            }
          } else {
            console.log("getSyjgLdzsChild接口出错！");
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
	
	changehandle(val){
		this.currentPage=1;
		this.pagesize=12;
		this.handle(val,this.currentPage,this.pagesize);
	},
	async handle(val,currentPage,pagesize){
		this.$emit('updateTitle',val);
		this.val=val;
		this.ifshow=true;
		
		this.lableName=val;
		var depCode="";
		var doquery="";
		if (this.depCode == "") {
		  depCode = "36%";
		}else{
			depCode=this.depCode;
		}
		if (val == "省部级正职数") {
		 doquery = "sbjzzbz";
		} else if (val == "省部级副职数") {
		  doquery = "sbjfzbz";
		}  else if (val == "厅局级正职数") {
		  doquery = "tjjzzbz";
		} else if (val == "厅局级副职数") {
		  doquery = "tjjfzbz";
		}  else if (val == "县处级正职数") {
		  doquery = "xcjzzbz";
		}  else if (val == "县处级副职数") {
		  doquery = "xcjfzbz";
		}  else if (val == "乡科级正职数") {
		  doquery = "xkjzzbz";
		}  else if (val == "乡科级副职数") {
		  doquery = "xkjfzbz";
		}  else if (val == "股级正职数") {
		  doquery = "gjzzbz";
		} else if (val == "股级副职数") {
		  doquery = "gjfzbz";
		} else if (val == "未定级领导职数") {
		  doquery = "wdjbzs";
		} else if (val == "其他领导职数") {
		  doquery = "qtbzs";
		}  else if (val == "省部级正职在职数") {
		  doquery = "sbjzzzz";
		}  else if (val == "省部级副职在职数") {
		  doquery = "sbjfzzz";
		}  else if (val == "厅局级正职在职数") {
		  doquery = "tjjzzzz";
		} else if (val == "厅局级副职在职数") {
		  doquery = "tjjfzzz";
		} else if (val == "县处级正职在职数") {
		  doquery = "xcjzzzz";
		}  else if (val == "县处级副职在职数") {
		  doquery = "xcjfzzz";
		}  else if (val == "乡科级正职在职数") {
		  doquery = "xkjzzzz";
		}  else if (val == "乡科级副职在职数") {
		  doquery = "xkjfzzz";
		}  else if (val == "股级正职在职数") {
		  doquery = "gjzzzz";
		}  else if (val == "股级副职在职数") {
		  doquery = "gjfzzz";
		}  else if (val == "未定级在职数") {
		  doquery = "wdjzzs";
		}  else if (val == "其他在职数") {
		  doquery = "qtzzs";
		} else{
			return
		}
		await Sever.smz
		  .getSydwLdzsChildDetail({ depCode: depCode, doquery: doquery,pageNum:currentPage,pageSize:pagesize })
		  .then((res) => {
		    if (res.code == 1) {
		      if (res.data != null) {
						console.log(res.data);
		     this.tableChildData = res.data.list;
		     this.total = res.data.total;
		      } else {
		        this.tableChildData = [];
		      }
		    } else {
		      console.log("getSydwLdzsChildDetail接口出错！");
		    }
		  })
		  .catch((err) => {
		    console.log(err);
		  });
		
	}
  },
  mounted() {
    this.$nextTick(() => {
      this.refreshData(this.depCode, this.ldzstype,this.currentPage,this.pagesize);
    });
  },
};
</script>